//
//  URLUtils.swift
//  cloud
//
//  Created by 吳瀾洲 on 2020/7/8.
//  Copyright © 2020 kingboyrang. All rights reserved.
//

import UIKit

class URLUtils: NSObject {

    //静态方法
    static let shared = URLUtils()
    
    //保存配置
    func save(ip:String) -> Void {
        
        CacheDataUtil.setCache(value: ip as AnyObject, key: kCacheServerIP);
        let url:String = "http://\(ip)/api/";
        CacheDataUtil.setCache(value: url as AnyObject, key: kCacheServerURL);
    }
    
    //获取服务器ip
    func getServerIp() -> String {
        
        if let value:String = CacheDataUtil.valueForKey(key: kCacheServerIP) as? String{
            return value;
        }else{
            return Cloud_SERVER_IP;
        }
    }
    
    //获取请求url
    func getRequestURL(method:String) -> String {
        if let value:String = CacheDataUtil.valueForKey(key: kCacheServerURL) as? String{
            return value + method;
        }else{
            return Cloud_SERVER_URL + method;
        }
    }
}
